package com.bridgeintelligent.tag.engine.mvc;

import com.bridgeintelligent.tag.engine.api.rsp.CommonRsp;
import com.bridgeintelligent.tag.engine.core.cache.CacheConfig;
import com.bridgeintelligent.tag.engine.core.cache.CacheUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created by JackCheung on 2019/10/21 8:09 PM.
 */
@Api(tags = "引擎工具模块")
@AllArgsConstructor
@RestController
@RequestMapping(value = "/api/engine/utils")
@Slf4j
public class EngineUtilsController {

    private EngineUtilsService engineUtilsService;

    @ApiOperation(value = "最新数据日期查询", notes = "引擎查询模块")
    @GetMapping("/date/{themeId}")
    @ApiImplicitParam(paramType = "path", name = "themeId", value = "主题id", required = true)
    public CommonRsp dataSet(@PathVariable String themeId) {
        return engineUtilsService.date(themeId);
    }

    /**
     * 刷新所有服务器的
     *
     * @return
     */
    @ApiOperation(value = "刷新引擎缓存", notes = "引擎查询模块")
    @GetMapping("/refresh")
    public CommonRsp refresh() {
        log.info("开始刷新引擎缓存");
        CommonRsp commonRsp = engineUtilsService.refreshAll();
        log.info("开始刷新引擎缓存："+ CacheUtils.getCacheMap(CacheConfig.CONFIGURATION_INFO));
        return commonRsp;
    }

    /**
     * 刷新单台服务器的
     *
     * @return
     */
    @ApiOperation(value = "刷新引擎缓存", notes = "引擎查询模块")
    @GetMapping("/refreshItem")
    public CommonRsp refreshItem() {
        return engineUtilsService.refreshItem();
    }
}
